//
//  WYMediaDetailController.m
//  CirclePush
//
//  Created by admin on 2018/5/19.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYMediaDetailController.h"
#import "WYRecommendCell.h"
#import "WYMediaDetailMessageCell.h"
#import "WYMediaDetailBasicMessageCell.h"
#import "WYFormBascCell.h"
#import "WYResourceCell.h"
#import "WYDetailMediaModel.h"
#import "WYPopMediaView.h"

#import "WYShareBottomView.h"




@interface WYMediaDetailController ()<UITableViewDelegate,UITableViewDataSource,WKNavigationDelegate,WKUIDelegate,WYMediaDetailMessageCellDelegate,WYResourceCellDelegate>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic, strong) SDCycleScrollView *advView;
@property (nonatomic,strong)UIImageView *lineView;
@property (nonatomic,strong)WYDetailMediaModel *detailModel;
@property (nonatomic,strong) WYPopMediaView *popView;
@property (nonatomic,strong)NSMutableArray *dataArray;

@property (nonatomic,strong)WYResourceCell *resourceCell;

@property (nonatomic,strong)WYShareBottomView *shareBottomView;



@end

@implementation WYMediaDetailController
{
    CGFloat _height;
}
-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.view.backgroundColor = [UIColor whiteColor];
    [self loadData];
    [self loadRemData];
    WEAKSELF
    [self compressedImageFiles:self.image imageKB:32 imageBlock:^(UIImage *image) {
        weakSelf.shareBottomView.shareImage = image;
        
        
    }];
    
    
    // Do any additional setup after loading the view.
}
-(void)loadData
{
    WEAKSELF
    [WYHttpServer getMediaDetailWithID:self.ID SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            weakSelf.detailModel = [WYDetailMediaModel getDeatilModelFormJson:response[@"result"]];
            [weakSelf.tableView reloadData];
            [weakSelf.advView setImageURLStringsGroup:[weakSelf.detailModel.media.bannerImage componentsSeparatedByString:@","]];
            [weakSelf setBarItem];
        }
    }];
}
-(void)setBarItem
{
    UIBarButtonItem *item = self.navigationItem.rightBarButtonItems[1];
    if (self.detailModel.collect.intValue) {
        item.tintColor = [UIColor blueColor];
    }else{
       // item.tintColor = [UIColor whiteColor];
    }
}
-(void)loadRemData
{
    WEAKSELF
    [WYHttpServer getRecommendMediaListWithmediaId:@"" Witharea:@"" WithPageNum:@"1" WithPageSize:@"10" SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        
        NSLog(@"%@",errorMessage);
        if (success) {
            if ([WYMedia getMediaListFromJson:response[@"result"]].count) {
//                [weakSelf.dataArray addObject:[WYMedia getMediaListFromJson:response[@"result"]]];
                NSArray *array =[WYMedia getMediaListFromJson:response[@"result"]];
                if (array.count) {
                    for (int i=0; i<array.count; i++) {
                        [self.dataArray addObject:array[i]];
                    }
                }
                [weakSelf.tableView reloadData];
                [self.tableView.mj_footer endRefreshing];
            }
            
        }else{
            
        }
    }];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=NO;
    self.lineView = [self getLineViewInNavigationBar:self.navigationController.navigationBar];
    self.lineView.hidden = YES;
}
- (UIImageView *)getLineViewInNavigationBar:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self getLineViewInNavigationBar:subview];
        if (imageView) {
            return imageView;
        }
    }
    
    return nil;
}
-(void)setupUI
{
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_collection"] style:(UIBarButtonItemStyleDone) target:self action:@selector(clickRightCollection:)];

    UIBarButtonItem *rightItem1 = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_share"] style:(UIBarButtonItemStyleDone) target:self action:@selector(clickRightNavAction:)];
//
   self.navigationItem.rightBarButtonItems =@[rightItem1,rightItem];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_return"] style:(UIBarButtonItemStylePlain) target:self action:@selector(returnToTop)];
    
    
    CGFloat height = 0;
    if (kDevice_Is_iPhoneX) {
        height = 88;
    }else{
        height = 64;
    }
    self.tableView.contentInset = UIEdgeInsetsMake(IMAGE_HEIGHT, 0, 0, 0);
    [self.tableView addSubview:self.advView];
    // 设置导航栏颜色
    [self wr_setNavBarBarTintColor:[UIColor whiteColor]];
    
    // 设置初始导航栏透明度
    [self wr_setNavBarBackgroundAlpha:0];
    
    // 设置导航栏按钮和标题颜色
    [self wr_setNavBarTintColor:[UIColor whiteColor]];
    // 设置导航栏按钮和标题颜色
    [self wr_setNavBarTintColor:[UIColor whiteColor]];
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"WYRecommendCell" bundle:nil] forCellReuseIdentifier:@"WYRecommendCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYMediaDetailMessageCell" bundle:nil] forCellReuseIdentifier:@"WYMediaDetailMessageCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"WYMediaDetailBasicMessageCell" bundle:nil] forCellReuseIdentifier:@"WYMediaDetailBasicMessageCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"WYFormBascCell" bundle:nil] forCellReuseIdentifier:@"WYFormBascCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"WYResourceCell" bundle:nil] forCellReuseIdentifier:@"WYResourceCell"];
    
    [self.view addSubview:self.tableView];
    
    UIView *bottomView = [[UIView alloc]init];
    [self.view addSubview:bottomView];
    CGFloat bottomHeight = 0;
    if (kDevice_Is_iPhoneX) {
        bottomHeight = 83;
    }else{
        bottomHeight = 49;
    }
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_offset(0);
        make.height.mas_equalTo(bottomHeight);
    }];
    
    UIButton *consultationBtn = [[UIButton alloc]init];
    [bottomView addSubview:consultationBtn];
    [consultationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(kScreenWidth/2);
    }];
    [consultationBtn setTitle:@"咨询媒体档期" forState:UIControlStateNormal];
//    [consultationBtn setBackgroundColor:[UIColor hexStringToColor:@"22d360" alpha:1.0]];
    [consultationBtn setBackgroundColor:RGBA(233, 239, 247, 1.0)];
    [consultationBtn setTitleColor:RGBA(0, 130, 249, 1.0) forState:UIControlStateNormal];
    [consultationBtn addTarget:self action:@selector(clickConsultationBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *priceBtn = [[UIButton alloc]init];
    [bottomView addSubview:priceBtn];
    [priceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(kScreenWidth/2);
    }];
    
    [priceBtn setTitle:@"申请合作" forState:UIControlStateNormal];
    [priceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [priceBtn setBackgroundColor:RGBA(0, 130, 249, 1.0)];
    [priceBtn addTarget:self action:@selector(clickPriceBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    //self.tableView.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:self.shareBottomView];
}
-(void)returnToTop
{
    [self.navigationController popViewControllerAnimated:YES];
}



-(void)clickConsultationBtnAction:(UIButton *)btn
{
    [self showAlertMessage];
    
}

-(void)showAlertMessage
{
    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", @"400-6762-9898"];
    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }
//    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"400-6762-9898" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
//    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//    }];
//
//    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//    }];
//    [alertController addAction:action1];
//    [alertController addAction:action2];
//    [self presentViewController:alertController animated:YES completion:nil];
    
}


-(void)clickPriceBtnAction:(UIButton *)btn
{
    WEAKSELF
    WYPopMediaView *popView = [WYPopMediaView getPopView];
    self.popView = popView;
    [popView setCornerRadius:10.0f];
    popView.frame = CGRectMake(10, 200, kScreenWidth-20, 400);
    popView.complete = ^(NSUInteger index, NSString *userName, NSString *userMobile, NSString *userEmail) {
        if (index) {
            if (!userName.length) {
                [weakSelf toast:@"请输入联系人姓名"]; return ;
            }
            if (!userMobile.length) {
                [weakSelf toast:@"请输入手机号"]; return ;
            }
            [weakSelf updateMessageWithUserMessage:userName WithTelephone:userMobile WithEmail:userEmail];
            
            
        }else{
      
        }
        [weakSelf.popView removeFromSuperview];
        [weakSelf.maskView removeFromSuperview];
    };
    
    
   // [self.view addSubview:popView];
    [[UIApplication sharedApplication].keyWindow addSubview:self.maskView];
    [[UIApplication sharedApplication].keyWindow addSubview:popView];
    
    
}
-(void)updateMessageWithUserMessage:(NSString *)userMessage WithTelephone:(NSString *)phone WithEmail:(NSString *)email
{
    WEAKSELF
    [WYHttpServer submissiondemandWithLinkeMan:userMessage WithTelephone:phone WithEmail:email WithMediaType:@"2" WithMediaId:self.ID SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            [weakSelf toast:@"提交成功"];
        }else{
            [weakSelf toast:errorMessage];
        }
        
        
        
    }];
}



-(void)clickRightNavAction:(UIBarButtonItem *)item
{
    
    
    
    [self.shareBottomView setKLinkURL:@"http://sj.qq.com/myapp/detail.htm?apkName=com.zqzx.generalizecircle"];
    [self.shareBottomView setKLinkTitle:self.media.mediaTitle];
    
    if (self.media.publishPrice.longLongValue/100>10000) {
        if (self.media.launchCycle.length) {
            self.shareBottomView.kLinkDescription =[NSString stringWithFormat:@"%.2f万/%@",self.media.publishPrice.longLongValue/100/10000.0,self.media.launchCycle];
        }else{
            self.shareBottomView.kLinkDescription =[NSString stringWithFormat:@"%.2f万",self.media.publishPrice.longLongValue/100/10000.0];
        }
        
    }else{
        if (self.media.launchCycle.length) {
            self.shareBottomView.kLinkDescription =[NSString stringWithFormat:@"%lld/%@",self.media.publishPrice.longLongValue/100,self.media.launchCycle];
        }else{
            self.shareBottomView.kLinkDescription =[NSString stringWithFormat:@"%lld",self.media.publishPrice.longLongValue/100];
        }
        
        
        
    }
    
    self.shareBottomView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
}

- (void)compressedImageFiles:(UIImage *)image
                     imageKB:(CGFloat)fImageKBytes
                  imageBlock:(void(^)(UIImage *image))block {
    
    __block UIImage *imageCope = image;
    CGFloat fImageBytes = fImageKBytes * 1024;//需要压缩的字节Byte
    
    __block NSData *uploadImageData = nil;
    
    uploadImageData = UIImagePNGRepresentation(imageCope);
    NSLog(@"图片压前缩成 %fKB",uploadImageData.length/1024.0);
    CGSize size = imageCope.size;
    CGFloat imageWidth = size.width;
    CGFloat imageHeight = size.height;
    
    if (uploadImageData.length > fImageBytes && fImageBytes >0) {
        
        dispatch_async(dispatch_queue_create("CompressedImage", DISPATCH_QUEUE_SERIAL), ^{
            
            /* 宽高的比例 **/
            CGFloat ratioOfWH = imageWidth/imageHeight;
            /* 压缩率 **/
            CGFloat compressionRatio = fImageBytes/uploadImageData.length;
            /* 宽度或者高度的压缩率 **/
            CGFloat widthOrHeightCompressionRatio = sqrt(compressionRatio);
            
            CGFloat dWidth   = imageWidth *widthOrHeightCompressionRatio;
            CGFloat dHeight  = imageHeight*widthOrHeightCompressionRatio;
            if (ratioOfWH >0) { /* 宽 > 高,说明宽度的压缩相对来说更大些 **/
                dHeight = dWidth/ratioOfWH;
            }else {
                dWidth  = dHeight*ratioOfWH;
            }
            
            imageCope = [self drawWithWithImage:imageCope width:dWidth height:dHeight];
            uploadImageData = UIImagePNGRepresentation(imageCope);
            
            NSLog(@"当前的图片已经压缩成 %fKB",uploadImageData.length/1024.0);
            //微调
            NSInteger compressCount = 0;
            /* 控制在 1M 以内**/
            while (fabs(uploadImageData.length - fImageBytes) > 1024) {
                /* 再次压缩的比例**/
                CGFloat nextCompressionRatio = 0.9;
                
                if (uploadImageData.length > fImageBytes) {
                    dWidth = dWidth*nextCompressionRatio;
                    dHeight= dHeight*nextCompressionRatio;
                }else {
                    dWidth = dWidth/nextCompressionRatio;
                    dHeight= dHeight/nextCompressionRatio;
                }
                
                imageCope = [self drawWithWithImage:imageCope width:dWidth height:dHeight];
                uploadImageData = UIImagePNGRepresentation(imageCope);
                
                /*防止进入死循环**/
                compressCount ++;
                if (compressCount == 10) {
                    break;
                }
                
            }
            
            NSLog(@"图片已经压缩成 %fKB",uploadImageData.length/1024.0);
            imageCope = [[UIImage alloc] initWithData:uploadImageData];
            
            dispatch_sync(dispatch_get_main_queue(), ^{
                block(imageCope);
            });
        });
    }
    else
    {
        block(imageCope);
    }
}
/* 根据 dWidth dHeight 返回一个新的image**/
- (UIImage *)drawWithWithImage:(UIImage *)imageCope width:(CGFloat)dWidth height:(CGFloat)dHeight{
    
    UIGraphicsBeginImageContext(CGSizeMake(dWidth, dHeight));
    [imageCope drawInRect:CGRectMake(0, 0, dWidth, dHeight)];
    imageCope = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return imageCope;
    
}

-(void)clickRightCollection:(UIBarButtonItem *)item
{
    WEAKSELF
    if (self.detailModel.collect.intValue) {
        [WYHttpServer delegateCollectionWithMediaId:self.ID SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
            
            if (success) {
                [weakSelf loadData];
                [weakSelf toast:@"取消收藏成功"];
            }else{
                [weakSelf toast:errorMessage];
                
            }
            
        }];
       
        
    }else{
       
        [WYHttpServer addCollectionWithMediaId:self.ID SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
            if (success) {
                [weakSelf loadData];
                [weakSelf toast:@"收藏成功"];
            }else{
                [weakSelf toast:errorMessage];
                
            }
        }];
    }
//    NSLog(@"1111111111111111111111");
//    item.tintColor = [UIColor blueColor];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 4;
    }else{
        return self.dataArray.count;
    }
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        
        if (indexPath.row==0) {
            WYMediaDetailMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYMediaDetailMessageCell" forIndexPath:indexPath];
            if (!cell) {
                cell = [[NSBundle mainBundle]loadNibNamed:@"WYMediaDetailMessageCell" owner:nil options:nil].firstObject;
            }
            
            if (self.detailModel) {
                [cell setType:self.detailModel.mediaType];
                [cell setModel:self.detailModel.media];
            }
            cell.delegate = self;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        
        if (indexPath.row==1) {
            WYMediaDetailBasicMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYMediaDetailBasicMessageCell" forIndexPath:indexPath];
            if (!cell) {
                cell = [[NSBundle mainBundle]loadNibNamed:@"WYMediaDetailBasicMessageCell" owner:nil options:nil].firstObject;
            }
            if (self.detailModel) {
                cell.dataArray = self.detailModel.mapList;
                
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }
        if (indexPath.row==2) {
            WYFormBascCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYFormBascCell" forIndexPath:indexPath];
            
            if (!cell) {
                cell = [[NSBundle mainBundle]loadNibNamed:@"WYFormBascCell" owner:nil options:nil].firstObject;
            }
            if (self.detailModel) {
                cell.dataArray = self.detailModel.mediaSubsection;
                
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        if (indexPath.row==3) {
            WYResourceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYResourceCell" forIndexPath:indexPath];
            //        cell.webView.delegate = self;
            //        cell.webView.scrollView.bounces = NO;
            
            cell.webView.UIDelegate = self;
            cell.webView.navigationDelegate = self;
            self.resourceCell = cell;
            if (self.detailModel.media.mediaDescription.length) {
                cell.htmlString = self.detailModel.media.mediaDescription;
            }
            cell.delegate = self;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        return nil;
    }else{
        WYRecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYRecommendCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[NSBundle mainBundle] loadNibNamed:@"WYRecommendCell" owner:nil options:nil].firstObject;
        }
        WYMedia *media = self.dataArray[indexPath.row];
        [cell setMedia:media];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
   
    
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return nil;
    }else{
        UIView *view = [[UIView alloc]init];
        view.backgroundColor =[UIColor whiteColor];
        UIView *leftView = [[UIView alloc]init];
        [view addSubview:leftView];
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.top.mas_equalTo(10);
            make.bottom.mas_equalTo(-10);
            make.width.mas_equalTo(3);
        }];
        leftView.backgroundColor = RGBA(0, 130, 249, 1.0);
        
        UILabel *label = [[UILabel alloc]init];
        [view addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.centerY.mas_equalTo(view);
        }];
        
        label.text = @"媒体推荐";
        
        return view;
    }
  
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return 0.000000001;
    }
    return 40;
}



-(void)clickGetMinPrice
{
    [self showAlertMessage];
}
-(void)clickGetPPTBtn
{
    [self clickPriceBtnAction:nil];
}



//-(void)webViewDidFinishLoad:(UIWebView *)webView
//{
//      [self.tableView beginUpdates];
//    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
//    _height = height;
//    [self.tableView endUpdates];
//   // [self.tableView reloadData];
//}

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
{
    
    [webView evaluateJavaScript:@"document.getElementById(\"testDiv\").offsetTop"completionHandler:^(id _Nullable result,NSError * _Nullable error) {
        //获取页面高度，并重置webview的frame
        CGFloat lastHeight  = [result doubleValue];
        webView.frame = CGRectMake(14, 0, kScreenWidth - 28, lastHeight);
        _height = lastHeight;
        [self.tableView beginUpdates];
        [self.tableView endUpdates];
    }];
    
    
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            return 185;
        }
        if (indexPath.row==1) {
            if (self.detailModel.mapList.count) {
                NSMutableArray *nameArray = @[].mutableCopy;
                for (WYMapList *list in self.detailModel.mapList) {
                    if (list.name.length||list.attrName.length) {
                        if (list.value.length||list.attributeValue.length) {
                            [nameArray addObject:list];
                        }
                    }
                }
                return nameArray.count * 44;
            }
            return 0;
        }
        if (indexPath.row==2) {
            if (self.detailModel.mediaSubsection.count) {
                return self.detailModel.mediaSubsection.count *70;
            }
            
            return 0;
        }
        if (indexPath.row==3) {
            if (self.detailModel.media.mediaDescription.length) {
                return _height+50;
            }
            return 0;
        }
    }else{
        
    }
   
    return 120;
}



- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY > 64)
    {
        CGFloat alpha = (offsetY - 64) / 64;
        [self wr_setNavBarBackgroundAlpha:alpha];
        [self wr_setNavBarTintColor:[[UIColor blackColor] colorWithAlphaComponent:alpha]];
        [self wr_setNavBarTitleColor:[[UIColor blackColor] colorWithAlphaComponent:alpha]];
        [self wr_setStatusBarStyle:UIStatusBarStyleDefault];
       // self.title = @"wangrui460";
    }
    else
    {
        [self wr_setNavBarBackgroundAlpha:0];
        [self wr_setNavBarTintColor:[UIColor whiteColor]];
        [self wr_setNavBarTitleColor:[UIColor whiteColor]];
        [self wr_setStatusBarStyle:UIStatusBarStyleLightContent];
        //self.title = @"";
    }
    
    if (scrollView==self.tableView) {
        [self.resourceCell.webView setNeedsLayout];
    }

}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
        _tableView = [[WYTableView alloc] initWithFrame:frame
                                                  style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (SDCycleScrollView *)advView
{
    if (_advView == nil) {
        NSArray *localImages = @[];
        _advView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, -IMAGE_HEIGHT, kScreenWidth, IMAGE_HEIGHT) imageNamesGroup:localImages];
        _advView.pageDotColor = [UIColor grayColor];
        _advView.autoScrollTimeInterval = 2;
        _advView.currentPageDotColor = [UIColor whiteColor];
        _advView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    }
    return _advView;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        
    }else{
        WYMediaDetailController *mdc = [[WYMediaDetailController alloc]init];
        WYMedia *media = self.dataArray[indexPath.row];
        mdc.ID = media.id;
        [self.navigationController pushViewController:mdc animated:YES];
    }
    
  
}
-(WYShareBottomView *)shareBottomView
{
    if (!_shareBottomView) {
        _shareBottomView = [WYShareBottomView shareedShareBottomView];
        [_shareBottomView setBottomHeightStr:@""];
        _shareBottomView.frame = CGRectMake(0, kScreenHeight, kScreenWidth, kScreenHeight);
    }
    return _shareBottomView;
}


@end
